﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.BusinessLogicLayer;
public partial class CourseManagement_SearchCourseList :AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    public void Bind()
    {

        CourseModule cm = new CourseModule();
        DataSet ds = new DataSet();
        ds = cm.QueryAllCourseBySID(this.SchoolID);
        Repeater1.DataSource = getPage(ds);
        Repeater1.DataBind();
    }
    protected void BtCheck_Click(object sender, EventArgs e)
    {
        
        string name = TxtCheckCourse.Text.Trim();
        if (name == "" || name == null)
        { Bind(); }
        else
        {
            CheckBind(this.SchoolID, name);
        }

    }
    public void CheckBind(int sid, string name)
    {
        CourseModule cm = new CourseModule();
        DataSet ds = new DataSet();
        ds = cm.QueryAllCourseBySIDAndName(this.SchoolID, name);
        Repeater1.DataSource = getPage(ds);
        Repeater1.DataBind();
    }
    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        string name = TxtCheckCourse.Text.Trim();
        if (name == "" || name == null)
        { Bind(); }
        else
        {
            CheckBind(this.SchoolID, name);
        }
    }
    public void btnUpdate_Click(object sender, CommandEventArgs e)
    {
        Response.Redirect("UpdateCourse.aspx?CID=" + e.CommandArgument.ToString());
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddCourse.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("QuantityAddCourseInfo.aspx");
    }
    /// <summary>
    /// 根据选择删除数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {
        int id = int.Parse(e.CommandArgument.ToString());
        CourseModule cm = new CourseModule();
        cm.DeleteCourseList(id);
        Response.Redirect("SearchCourseList.aspx");
    }
}
